<template>
	<view class="m-carousel" :style="[initialStyle]">
		<swiper class="swiper" :autoplay="true" :circular="true" :display-multiple-items="1" @change="change">
			<swiper-item class="swiper-item" v-for="(item,index) in list" :key="index"
				@click="openimg(index,list,attribute)">
				<image class="swiper-item-img" :src="item[attribute]" mode="aspectFill">
				</image>
			</swiper-item>
		</swiper>
		<view class="dots-box" :style="{bottom:bottom}">
			<view :class="isindex === index ? 'dots dotsX' : 'dots'" v-for="(item,index) in list" :key="index">
			</view>
		</view>
	</view>
</template>

<script>
	import {
		openimg
	} from "@/utils/index.js"

	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			},
			borderRadius: {
				type: [String, Number],
				default: 0
			},
			attribute: {
				type: String,
				default: 'img'
			},
			bottom: {
				type: String,
				default: '20rpx'
			}
		},
		data() {
			return {
				isindex: 0,
			}
		},
		computed: {
			initialStyle() {
				const style = {}
				style.borderRadius = `${this.borderRadius}rpx`;
				return style;
			}
		},
		methods: {
			openimg,
			change(e) {
				this.isindex = e.detail.current
			}
		}
	}
</script>

<style lang="scss" scoped>
	.m-carousel {
		position: relative;
		width: 100%;
		height: 100%;
		overflow: hidden;

		.swiper {
			width: 100%;
			height: 100%;

			.swiper-item {
				width: 100%;
				height: 100%;

				.swiper-item-img {
					width: 100%;
					height: 100%;
				}
			}
		}

		.dots-box {
			position: absolute;
			bottom: 20rpx;
			z-index: 2;
			width: 100%;
			height: 20rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;

			.dots {
				width: 10rpx;
				height: 10rpx;
				border-radius: 5rpx;
				margin: 0 10rpx 0 10rpx;
				background-color: #efefef;
				/* #ifndef APP-PLUS-NVUE*/
				transition: all 400ms;
				/*  #endif  */
			}

			.dotsX {
				width: 30rpx;
				border-radius: 15rpx;
				/* #ifndef APP-PLUS-NVUE*/
				transition: all 400ms;
				/*  #endif  */
			}
		}
	}
</style>